<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <link href="../../css/style.css" rel="stylesheet" type="text/css">
    <script language="JavaScript" type="text/javascript" src="../../js/win_center.js"></script>
    <script src="../../bootstrap-3.3.7-dist/js/jquery-3.4.1.min.js"></script>
    <script language="javascript">
        function windowOpen(theURL, winName, features, width, hight, scrollbars, top, left) {
            var parameter = "top=" + top + ",left=" + left + ",width=" + width + ",height=" + hight;
            if (scrollbars == "no") {
                parameter += ",scrollbars=no";
            } else {
                parameter += ",scrollbars=yes";
            }
            window.open(theURL, winName, parameter);
        }

    </script>
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<center>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td height="25" align="center" valign="bottom" class="td06">
                <table width="98%" border="0" cellspacing="3" cellpadding="0">

                    <tr>
                        <td width="15"><img src="../../images/index_32.gif" width="9" height="9"></td>
                        <td valign="bottom" class="title">人员管理</td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
    <br>
    <table width="95%" border="0" cellspacing="0" cellpadding="0">

        <tr>
             <td align="left" class="td_page">请选择类型:<select name="" class="_select" >
                <option value="statel">员工电话</option>
                <option value="staname">员工姓名</option>
                <select><input   width="100%"  placeholder="请输入查询条件" class="search" ><input name="Submit" type="button" class="buttonface02"  value=" 搜索 " id="sbs">

            <td align="right" class="td_page">
            <input name="Submit" type="button" class="buttonface02" onClick="javascript:openwindow('addrole.htm?token='+location.href.split('=')[1],'',500,300)" value=" 添加 ">
        </td>

        </tr>
    </table>
    <form name="form1" method="post" action="">
        <table width="95%" border="0" cellspacing="2" cellpadding="0">
            <tr>
                <td class="td_title"> 当前员工信息</td>
            </tr>
        </table>
        <table width="95%" border="0" align="center" cellpadding="0" cellspacing="0" class="table01">
            <tr>
<!--                <td align="center" class="td_top"><input type="checkbox" name="checkbox" value="checkbox"></td>-->
                <td class="td_top">员工编号</td>
                <td class="td_top">员工姓名</td>
                <td class="td_top">员工性别</td>
                <td class="td_top">员工年龄</td>
                <td class="td_top">员工住址</td>
                <td class="td_top">员工电话</td>
                <td class="td_top">所属科室</td>
                <td class="td_top">员工工号</td>
                <td class="td_top">员工职位</td>
                <td class="td_top">操作</td>
            </tr>
        </table>
    </form>
</center>
</body>
</html>
<script>

    // 处理输出的职位信息，把json对象数组中职位名称转换为字符串输出
    function testjson(myjson) {
        var arr = [];
        myjson.forEach(function (value, index, a) {
            arr[arr.length] = value.position.postitle;
        });
        return arr.join();
    }

    // function Obtaindepid(myjson) {
    //   var arr = [];
    //   myjson.forEach(function (value, index, a) {
    //     arr[arr.length] = value.position.posid;
    //   });
    //   return arr.join();
    // }

    //修改用户信息
    $(function () {
        // location.reload
        $.ajax({
            url: "/feign/staffinfo/select",
            type: "get",
            dataType: "json",
            headers: {
                            Accept: "application/json; charset=utf-8",
                            Authorization: location.href.split("=")[1]
                        },
            success: function (data) {

                // alert(data);
                var html = "";
                // for(var i=0;i<data.length;i++){
                //     // console.log(data[i].department.deptype)
                //     // console.log(data[i].depid)
                //     console.log("length:"+data[i].staffinfoandpositionList.length)
                //     for(var m=0; m<data[i].staffinfoandpositionList.length; m++){
                //
                //          console.log("职位："+data[i].staffinfoandpositionList[m].position.postitle);
                //     }
                // }
                for (var i = 0; i < data.data.length; i++) {
                    html += '<tr>' +
                        // "<td align=\"center\" class=\"td_02\"><input type=\"checkbox\" name=\"checkbox\" value=\"checkbox\"></td>" +
                        "<td class=\"td_01\">" + data.data[i].staid + "</td>" +
                        "<td class=\"td_01\">" + data.data[i].staname + "</td>" +
                        "<td class=\"td_01\">" + data.data[i].stasex + "</td>" +
                        "<td class=\"td_01\">" + data.data[i].staage + "</td>" +
                        "<td class=\"td_01\">" + data.data[i].staaddress + "</td>" +
                        "<td class=\"td_01\">" + data.data[i].statel + "</td>" +
                        "<td class=\"td_01\">" + data.data[i].department.deptype + "</td>" +
                        "<td class=\"td_01\">" + data.data[i].stajobnumber + "</td>" +
                        "<td class=\"td_01\">" + testjson(data.data[i].staffinfoandpositionList) + "</td>" +
                        "<td align=\"right\" class=\"td_page\"><input name=\"Submit\" type=\"button\" class=\"buttonface02\" onClick=\"javascript:openwindow('delete.html?token="+location.href.split("=")[1]+"&" + data.data[i].staid + "&" + data.data[i].staname + "&" + data.data[i].stasex + "&" + data.data[i].staage + "&" + data.data[i].staaddress + "&" + data.data[i].statel + "&" + data.data[i].department.deptype + "&" + testjson(data.data[i].staffinfoandpositionList) + "','',500,300)\" value=\" 修改员工信息 \">   <input name=\"Submit\" id='submit' type=\"button\" class=\"buttonface02\"  value=\" 删除 \" >  </td>" +
                        +'</tr>'
                }
                $(".table01").append(html);
                $("body").on("click","#submit",function () {
                    show_confirm(this)
                })
            }
        });
    });



    //
    // // 处理输出的职位信息，把json对象数组中职位名称转换为字符串输出
    // function testjson(myjson) {
    //     var arr = [];
    //     myjson.forEach(function (value, index, a) {
    //         arr[arr.length] = value.position.postitle;
    //     });
    //     return arr.join();
    // }
    //
    // // function Obtaindepid(myjson) {
    // //   var arr = [];
    // //   myjson.forEach(function (value, index, a) {
    // //     arr[arr.length] = value.position.posid;
    // //   });
    // //   return arr.join();
    // // }
    //
    // //修改用户信息
    // $(function () {
    //     // location.reload
    //     $.ajax({
    //         url: "/feign/staffinfo/select",
    //         type: "get",
    //         dataType: "json",
    //         headers: {
    //             Accept: "application/json; charset=utf-8",
    //             Authorization: location.href.split("=")[1]
    //         },
    //         success: function (data) {
    //
    //             alert(data);
    //             var html = "";
    //             // for(var i=0;i<data.length;i++){
    //             //     // console.log(data[i].department.deptype)
    //             //     // console.log(data[i].depid)
    //             //     console.log("length:"+data[i].staffinfoandpositionList.length)
    //             //     for(var m=0; m<data[i].staffinfoandpositionList.length; m++){
    //             //
    //             //          console.log("职位："+data[i].staffinfoandpositionList[m].position.postitle);
    //             //     }
    //             // }
    //
    //             $.each(data,function (i,obj) {
    //                 $(".table01").append("")
    //                 html += '<tr>' +
    //                     // "<td align=\"center\" class=\"td_02\"><input type=\"checkbox\" name=\"checkbox\" value=\"checkbox\"></td>" +
    //                     "<td class=\"td_01\">" + data[i].staid + "</td>" +
    //                     "<td class=\"td_01\">" + data[i].staname + "</td>" +
    //                     "<td class=\"td_01\">" + data[i].stasex + "</td>" +
    //                     "<td class=\"td_01\">" + data[i].staage + "</td>" +
    //                     "<td class=\"td_01\">" + data[i].staaddress + "</td>" +
    //                     "<td class=\"td_01\">" + data[i].statel + "</td>" +
    //                     "<td class=\"td_01\">" + data[i].department.deptype + "</td>" +
    //                     "<td class=\"td_01\">" + data[i].stajobnumber + "</td>" +
    //                     "<td class=\"td_01\">" + testjson(data[i].staffinfoandpositionList) + "</td>" +
    //                     "<td align=\"right\" class=\"td_page\"><input name=\"Submit\" type=\"button\" class=\"buttonface02\" onClick=\"javascript:openwindow('delete.html?token="+location.href.split("=")[1]+"&" + data[i].staid + "&" + data[i].staname + "&" + data[i].stasex + "&" + data[i].staage + "&" + data[i].staaddress + "&" + data[i].statel + "&" + data[i].department.deptype + "&" + testjson(data[i].staffinfoandpositionList) + "','',500,300)\" value=\" 修改员工信息 \">   <input name=\"Submit\" id='submit' type=\"button\" class=\"buttonface02\"  value=\" 删除 \" >  </td>" +
    //                     +'</tr>'
    //
    //             })
    //
    //             $(".table01").append(html);
    //             $("#submit").on("click",function () {
    //                 show_confirm(this)
    //             })
    //         }
    //     });
    // });




        //删除
        function show_confirm(obj) {
            var r = confirm("确认删除?");
            if (r) {
                $.ajax({
                    url: "/feign/staffinfo/delect/"+parseInt($(obj).parents("tr").children("td:first").html()),
                    type: "get",
                    headers: {
                        Accept: "application/json; charset=utf-8",
                        Authorization: location.href.split("=")[1]
                    },
                    success: function (data) {
                        if(data.code==200){

                        location.href ="rolelist.htm?token="+location.href.split("=")[1];
                        }
                    }
                });
            } else {
                alert("You pressed Cancel!");
            }
        }





        //搜索
        $("#sbs").on("click", function () {
            var _select = $('._select option:selected').val();
            if (_select == "statel") {
                $.ajax({
                    url: "/feign/staffinfo/search",
                    type: "get",
                    data: {
                        statel: $(".search").val()
                    },
                    dataType: "json",
                    headers: {
                        Accept: "application/json; charset=utf-8",
                        Authorization: location.href.split("=")[1]
                    },
                    success: function (data) {
                        var ht = "  <tr>\n" +
                            "<td class=\"td_top\">员工编号</td>\n" +
                            "<td class=\"td_top\">员工姓名</td>\n" +
                            "<td class=\"td_top\">员工性别</td>\n" +
                            "<td class=\"td_top\">员工年龄</td>\n" +
                            "<td class=\"td_top\">员工住址</td>\n" +
                            "<td class=\"td_top\">员工电话</td>\n" +
                            "<td class=\"td_top\">所属科室</td>\n" +
                            "<td class=\"td_top\">员工工号</td>\n" +
                            "<td class=\"td_top\">员工职位</td>\n" +
                            "<td class=\"td_top\">操作</td>\n" +
                            "</tr>";
                        for (var i = 0; i < data.data.length; i++) {
                            ht += '<tr>' +
                                "<td class=\"td_01\">" + data.data[i].staid + "</td>" +
                                "<td class=\"td_01\">" + data.data[i].staname + "</td>" +
                                "<td class=\"td_01\">" + data.data[i].stasex + "</td>" +
                                "<td class=\"td_01\">" + data.data[i].staage + "</td>" +
                                "<td class=\"td_01\">" + data.data[i].staaddress + "</td>" +
                                "<td class=\"td_01\">" + data.data[i].statel + "</td>" +
                                "<td class=\"td_01\">" + data.data[i].department.deptype + "</td>" +
                                "<td class=\"td_01\">" + data.data[i].stajobnumber + "</td>" +
                                "<td class=\"td_01\">" + testjson(data.data[i].staffinfoandpositionList) + "</td>" +
                                "<td align=\"right\" class=\"td_page\"><input name=\"Submit\" type=\"button\" class=\"buttonface02\" onClick=\"javascript:openwindow('delete.html?" + data.data[i].staid + "&" + data.data[i].staname + "&" + data.data[i].stasex + "&" + data.data[i].staage + "&" + data.data[i].staaddress + "&" + data.data[i].statel + "&" + data.data[i].department.deptype + "&" + testjson(data.data[i].staffinfoandpositionList) + "','',500,300)\" value=\" 修改员工信息 \">   <input name=\"Submit\" type=\"button\" class=\"buttonface02\"  value=\" 删除 \"    id=\"delects\"  <a onclick=\"show_confirm(this)\" href=\"/system/staffinfo/delect?staid=" + data.data[i].staid + "\" ></a></td>" +
                                +'</tr>'
                        }

                        $(".table01").html(ht);

                    }
                });
            } else {
                $.ajax({
                    url: "/feign/staffinfo/search",
                    type: "get",
                    data: {
                        staname: $(".search").val()
                    },
                    dataType: "json",
                    headers: {
                        Accept: "application/json; charset=utf-8",
                        Authorization: location.href.split("=")[1]
                    },
                    success: function (dat) {
                        var htm = "  <tr>\n" +
                            "<td class=\"td_top\">员工编号</td>\n" +
                            "<td class=\"td_top\">员工姓名</td>\n" +
                            "<td class=\"td_top\">员工性别</td>\n" +
                            "<td class=\"td_top\">员工年龄</td>\n" +
                            "<td class=\"td_top\">员工住址</td>\n" +
                            "<td class=\"td_top\">员工电话</td>\n" +
                            "<td class=\"td_top\">所属科室</td>\n" +
                            "<td class=\"td_top\">员工工号</td>\n" +
                            "<td class=\"td_top\">员工职位</td>\n" +
                            "<td class=\"td_top\">操作</td>\n" +
                            "</tr>";
                        for (var i = 0; i < dat.data.length; i++) {
                            htm += '<tr>' +
                                "<td class=\"td_01\">" + dat.data[i].staid + "</td>" +
                                "<td class=\"td_01\">" + dat.data[i].staname + "</td>" +
                                "<td class=\"td_01\">" + dat.data[i].stasex + "</td>" +
                                "<td class=\"td_01\">" + dat.data[i].staage + "</td>" +
                                "<td class=\"td_01\">" + dat.data[i].staaddress + "</td>" +
                                "<td class=\"td_01\">" + dat.data[i].statel + "</td>" +
                                "<td class=\"td_01\">" + dat.data[i].department.deptype + "</td>" +
                                "<td class=\"td_01\">" + dat.data[i].stajobnumber + "</td>" +
                                "<td class=\"td_01\">" + testjson(dat.data[i].staffinfoandpositionList) + "</td>" +
                                "<td align=\"right\" class=\"td_page\"><input name=\"Submit\" type=\"button\" class=\"buttonface02\" onClick=\"javascript:openwindow('delete.html?" + dat.data[i].staid + "&" + dat.data[i].staname + "&" + dat.data[i].stasex + "&" + dat.data[i].staage + "&" + dat.data[i].staaddress + "&" + dat.data[i].statel + "&" + dat.data[i].department.deptype + "&" + testjson(dat.data[i].staffinfoandpositionList) + "','',500,300)\" value=\" 修改员工信息 \">   <input name=\"Submit\" type=\"button\" class=\"buttonface02\"  value=\" 删除 \"    id=\"delects\"  <a onclick=\"show_confirm(this)\" href=\"/system/staffinfo/delect?staid=" + dat.data[i].staid + "\" ></a></td>" +
                                +'</tr>'
                        }
                        $(".table01").html(htm);


                    }
                });
            }
            ;
        });



    // $(".select02").click(function () {
    //     var _select= $('._select option:selected').val();
    //     if(_select=="staid"){
    //         $.ajax({
    //             url:"/drug/drugStorageController/findWaentry",
    //             type:"get",
    //             data:{"staid":$(".inputval").val(),"waedate":$(".waedate").val()},
    //             success:function (data) {
    //                 console.log(data)
    //             }
    //         })
    //     }else{
    //         $.ajax({
    //             url:"/drug/drugStorageController/findWaentry",
    //             type:"get",
    //             data:{"staname":$(".inputval").val(),"waedate":$(".waedate").val()},
    //             success:function (data) {
    //                 console.log(data)
    //             }
    //         })
    //     }
    //
    // })




    // //删除用户
    // $(function () {
    //   // alert($("#deletess").val())
    //   $.ajax({
    //     url: "/system/staffinfo/delect",
    //     type:"delete",
    //     data:{
    //       // "staid":$("#deletess").val()
    //     },
    //     dataType:"json",
    //     success:function (data){
    //
    //     }
    //   });
    // });


</script>
